package com.zhl.Demo;

public class Test2 {
    public static void main(String[] args) {
        //数组反转
        int[] sales = {16,20,25,3,53,63,61,21,78,89,35,29};
        int l = sales.length;
        int[] tem = new int[l];
        for (int i = 0; i < l;i++)
        {
            //数组最后一位的索引是-1
            tem[i] = sales[l-i-1];
        }
        //将tem数组的值赋给sales数组
        sales = tem;
        //打印查看是否反转成功
        for (int i = 0; i < l;i++)
        {
            System.out.print(sales[i] + " ");
        }

        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");

        //方法二 通过中间变量  进行前后交换
        int[] arr = {1,2,3,4,5};
        for (int i = 0,j = arr.length-1; i < j; i++,j--)
        {
            //arr[i] arr[j] 进行交换
            //定义一个中间变量 temp
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
        //打印查看是否反转成功
        for (int i = 0; i < arr.length;i++)
        {
            System.out.print(arr[i] + " ");
        }

    }
}
